<script setup>
import {useRoute} from "vue-router";
import {ruleTypeOptions, stateOptions} from "@/mixins/index.js";
import {useUserStore} from "@/store/index.js";
import {apiParam, fieldVisible} from "@/utils/index.js";
import {induce} from "@/utils/derive.js";
import {uuid} from "@/utils/random.js";
import {changeDateFormat, getNowDate} from "@/utils/time.js";
import {skyNoticeSuccess, skyNoticeError, skyMsgError, skyMsgWarning, skyMsgBox, skyMsgInfo, skyMsgSuccess} from "@/utils/sky.js";
import {getNewInfo} from "@/components/SkyWindow/index.js";
import {codeRulesApi} from "@/apis/PLM/frmCodeRules/index.js";
import {More} from "@element-plus/icons-vue";

const route = useRoute();
const userStore = useUserStore();
const skyDialogRef = ref();
const skyWindowRef = ref();
const formRef = ref();
const pageData = ref({
  props: {children: "child", label: "ProTypeName"},
  treeData: [],
  showSearch: true,
  searchParams: {
    keyWord: "",
    sort: "asc",
    manage: true,
  },
  codeRulesParams: {
    RuleCode: "",
    RuleName: "",
    ClassCode: "",
    ClassName: "",
  },
  pageParams: {
    pageIndex: 1,
    SortFields: "FRuleCode",
    direction: "asc",
    pageSize: 10,
  },
  ids: [],
  single: true,
  multiple: true,
  title: "编码规则",
  confirmLoading: false,
  form: {
    RuleType: "",
    ClassCode: "",
    ClassName: "",
    RuleCode: "",
    RuleName: "",
    IsValid: 1,
    SNumberLength: 0,
    FirstSNumber: 0,
    SNumberInterval: 0,
    BillDate: getNowDate(),
    Remark: "",
    Items: [],
    ItembyParam: [],
  },
  rules: {
    RuleCode: [{required: true, message: "请输入规则编号", trigger: "blur"}],
    RuleName: [{required: true, message: "请输入规则名称", trigger: "blur"}],
  },
  loading: false,
  total: 0,
  column: [],
  showTable: [
    {title: "编码分类", IsVisible: 1},
    {title: "类别编号", IsVisible: 1},
    {title: "类别名称", IsVisible: 1},
    {title: "规则编号", IsVisible: 1},
    {title: "规则名称", IsVisible: 1},
    {title: "有效码", IsVisible: 1},
    {title: "排序", IsVisible: 1},
    {title: "日期", IsVisible: 1},
    {title: "状态", IsVisible: 1},
    {title: "备注", IsVisible: 1},
  ],
  tableList: [],
  windowTitle: "",
  windowObj: {},
  windowParam: {},
  windowCond: {},
});
const method = reactive({
  /** 物料类别树 */
  handleListTree: async () => {
    const data = apiParam("2.0", "PLM.ProductTypesDAL.GetProTypeTrees", [0]);
    try {
      pageData.value.treeData = [];
      const res = await codeRulesApi(data);
      pageData.value.treeData = res.data;
    } catch (error) {
      skyMsgError("数据查询失败，请刷新重试🌻");
    }
  },
  /** 选择物料类别树 */
  handleCurrentChange: (val) => {
    pageData.value.codeRulesParams.ClassCode = val.ProTypeCode;
    pageData.value.codeRulesParams.ClassName = val.ProTypeName;
    method.handleListPage();
  },
  /** 关键字 */
  handleListKey: async () => {
    const data = apiParam("2.0", "PLM.CodeRulesDAL.Querybykeyvalue",
      [pageData.value.searchParams.keyWord,
        {
          pageNo: pageData.value.pageParams.pageIndex,
          ...pageData.value.pageParams
        }]);
    try {
      pageData.value.loading = true;
      pageData.value.tableList = [];
      const res = await codeRulesApi(data);
      pageData.value.searchParams.keyWord = "";
      pageData.value.total = res.data.recordsTotal;
      pageData.value.tableList = res.data.data;
      pageData.value.loading = false;
    } catch (error) {
      skyMsgError("数据查询失败，请刷新重试🌻");
    }
  },
  /** 搜索 */
  handleSearch: () => {
    pageData.value.pageParams.pageIndex = 1;
    method.handleListKey();
  },
  /** 重置 */
  resetSearch: () => {
    method.resetSearchParams();
    method.handleListPage();
  },
  /** 重置搜索参数 */
  resetSearchParams: () => {
    pageData.value.searchParams = {
      keyWord: "",
      sort: "asc",
      manage: true,
    };
    pageData.value.codeRulesParams = {
      RuleCode: "",
      RuleName: "",
      ClassCode: "",
      ClassName: "",
    };
    pageData.value.pageParams = {
      pageIndex: 1,
      SortFields: "FRuleCode",
      direction: "asc",
      pageSize: 10,
    };
  },
  /** 添加 */
  handleAdd: () => {
    // 打开弹出框
    skyDialogRef.value.skyOpen();
    // 重置表单
    method.resetForm();
    // 标题
    pageData.value.title = "添加";
    pageData.value.form.BillDate = getNowDate();
  },
  /** 选择编码分类 */
  handleChangeRuleType: async (e) => {
    const data = apiParam("2.0", "CMS.ParametersDAL.Querybypage",
      [{ParaType: e},
        {
          pageNo: 1,
          SortFields: "FParaCode",
          direction: "asc",
          pageSize: 100000,
        }]);
    try {
      const res = await codeRulesApi(data);
      pageData.value.form.ItembyParam = res.data.data.map(item => {
        return {
          RecordId: item.RecordId,
          CodeParaCode: item.ParaCode, // 参数编号
          CodeParaName: item.ParaName, // 参数名称
          CodeParaValue: "", // 编码值
          CodeNameValue: "", // 名称值
          SourceType: 0, // 参与编码
          IsMustFull: 0, // 是否必填
          ParaSourceType: item.ParaSourceType, // 是否字典
          isParams: true,
          Remark: item.Remark,
        }
      });
    } catch (error) {
      skyMsgError("数据查询失败，请刷新重试🌻");
    }
  },
  /** 选择物料分类 */
  handleChangeClass: (e) => {
    pageData.value.form.ClassCode = e.ProTypeCode;
    pageData.value.form.ClassName = e.ProTypeName;
  },
  /** 选择参数类型 */
  handleChangeSourceType: (val) => {
    const index = pageData.value.form.ItembyParam.findIndex(item => item.CodeParaName === val.CodeParaName);
    if (val.SourceType === 0 || val.SourceType === 1) {
      val.IsMustFull = 0;
    } else {
      // 参与编码
      val.IsMustFull = 1;
    }
    method.handleDealItem(index);
  },
  /** 处理数据 */
  handleDealItem: (index) => {
    const parma = pageData.value.form.ItembyParam[index];
    if (parma.SourceType === 2) {
      const obj = pageData.value.form.Items.find(item => item.CodeParaName === parma.CodeParaName);
      if (obj) {
        obj.CodeParaName = parma.CodeParaName;
        obj.CodeParaCode = parma.CodeParaCode;
        obj.CodeParaValue = parma.CodeParaValue;
        obj.CodeNameValue = parma.CodeNameValue;
      } else {
        pageData.value.form.Items.push({
          RecordId: uuid(),
          Sort: pageData.value.form.Items.length > 0 ? pageData.value.form.Items[pageData.value.form.Items.length - 1].Sort + 1 : 1,
          IsMustFull: parma.IsMustFull,
          SourceType: parma.SourceType,
          CodeParaName: parma.CodeParaName,
          CodeParaCode: parma.CodeParaCode,
          CodeParaValue: parma.CodeParaValue,
          CodeNameValue: parma.CodeNameValue,
          Linkstr: "",
          IsParameter: 1,
          ParaSourceType: parma.ParaSourceType,
          Remark: parma.Remark,
        });
      }
    } else {
      pageData.value.form.Items.forEach((item, index) => {
        if (item.CodeParaName === parma.CodeParaName) {
          pageData.value.form.Items.splice(index, 1);
        }
      });
    }
  },
  /** 新增行 */
  handleAddItems: () => {
    pageData.value.form.Items.push({
      RecordId: uuid(),
      Sort: pageData.value.form.Items.length > 0 ?
        pageData.value.form.Items[pageData.value.form.Items.length - 1].Sort + 1 : 1,
      IsMustFull: 0,
      SourceType: 0,
      CodeParaName: "",
      CodeParaValue: "",
      CodeNameValue: "",
      Linkstr: 0,
      IsParameter: 0,
      ParaSourceType: "其他",
      Remark: "",
    });
  },
  /** 删除行 */
  handleDeleteItems: (row) => {
    const id = row.RecordId;
    if (id === null || id === "") {
      skyMsgWarning("请选中需要删除的数据🌻");
      return;
    }
    skyMsgBox("您确认需要删除参数名称[" + row.CodeParaName + "]么？")
      .then(() => {
        try {
          const index = pageData.value.form.Items.find(item => item.RecordId === id);
          pageData.value.form.Items.splice(index, 1);
          skyNoticeSuccess("删除成功🌻");
        } catch (error) {
          skyNoticeError("删除失败，请刷新重试🌻");
        }
      })
      .catch(() => {
        skyMsgError("已取消🌻");
      });
  },
  /** 删除 */
  handleDelete: (row) => {
    const id = row.RecordId;
    if (id === null || id === "") {
      skyMsgWarning("请选中需要删除的数据🌻");
      return;
    }
    skyMsgBox("您确认需要删除参数名称[" + row.RuleName + "]么？")
      .then(async () => {
        try {
          const data = apiParam("2.0", "PLM.CodeRulesDAL.Delete", [id]);
          await codeRulesApi(data);
          await method.handleListPage();
          skyNoticeSuccess("删除成功🌻");
        } catch (error) {
          await method.handleListPage();
          skyNoticeError("删除失败，请刷新重试🌻");
        }
      })
      .catch(() => {
        skyMsgError("已取消🌻");
      });
  },
  /** 批量删除 */
  handleBatchDelete: () => {
    return skyMsgInfo("暂不支持批量删除");
  },
  /** 修改 */
  handleUpdate: (row) => {
    // 打开弹出框
    skyDialogRef.value.skyOpen();
    // 重置表单
    method.resetForm();
    pageData.value.title = "修改";
    const id = row ? row.RecordId : pageData.value.ids[0];
    if (id == null || id === "") {
      skyMsgError("请选中需要修改的数据🌻");
    }
    // 回显数据
    method.handleEcho(id);
  },
  /** 回显数据 */
  handleEcho: async (id) => {
    if (id === null || id === "") {
      skyMsgWarning("请选择需要修改的数据🌻");
      return;
    }
    try {
      const data = apiParam("2.0", "PLM.CodeRulesDAL.GetById", [id]);
      const res = await codeRulesApi(data);
      pageData.value.form = res.data;
    } catch (error) {
      skyNoticeError("数据获取失败，请刷新重试🌻");
    }
  },
  /** 确定  */
  handleConfirm: () => {
    if (!formRef.value) return;
    pageData.value.confirmLoading = true;
    (formRef.value).validate(async (valid) => {
      if (valid) {
        if (pageData.value.form.RecordId) {
          try {
            const data = apiParam("2.0", "PLM.CodeRulesDAL.Update",
              [pageData.value.form]);
            await codeRulesApi(data);
            skyNoticeSuccess("修改成功🌻");
            pageData.value.confirmLoading = false;
            skyDialogRef.value.skyQuickClose();
            method.resetForm();
            await method.handleListTree();
            await method.handleListPage();
          } catch (error) {
            pageData.value.confirmLoading = false;
            skyNoticeError("修改失败，请刷新重试🌻");
          }
        } else {
          try {
            const data = apiParam("2.0", "PLM.CodeRulesDAL.Create",
              [pageData.value.form]);
            await codeRulesApi(data);
            skyNoticeSuccess("添加成功🌻");
            pageData.value.confirmLoading = false;
            skyDialogRef.value.skyQuickClose();
            method.resetForm();
            await method.handleListTree();
            await method.handleListPage();
          } catch (error) {
            pageData.value.confirmLoading = false;
            skyNoticeError("添加失败，请刷新重试🌻");
          }
        }
      } else {
        skyMsgError("验证失败，请检查填写内容🌻");
        pageData.value.confirmLoading = false;
      }
    });
  },
  /** 取消 */
  handleCancel: () => {
    skyDialogRef.value.skyClose();
  },
  /** 清空表单数据 */
  resetForm: () => {
    nextTick(() => {
      if (formRef.value) {
        // 重置该表单项，将其值重置为初始值，并移除校验结果
        formRef.value.resetFields();
      }
    });
    pageData.value.form = {
      RuleType: "",
      ClassCode: "",
      ClassName: "",
      RuleCode: "",
      RuleName: "",
      IsValid: 1,
      SNumberLength: 0,
      FirstSNumber: 0,
      SNumberInterval: 0,
      BillDate: getNowDate(),
      Remark: "",
      Items: [],
      ItembyParam: [],
    };
  },
  /** 导出 */
  handleDerive: () => {
    const column = [
      {title: "字典类别编号", dataIndex: "DicTypeCode"},
      {title: "字典类别名称", dataIndex: "DicTypeName"},
      {title: "排序", dataIndex: "Sort"},
      {title: "日期", dataIndex: "BillDate"},
      {title: "状态", dataIndex: "State"},
      {title: "备注", dataIndex: "Remark"},
      {title: "录入人", dataIndex: "Creator"},
      {title: "录入时间", dataIndex: "CreateTime"},
      {title: "修改人", dataIndex: "LastModifier"},
      {title: "修改时间", dataIndex: "LastModifyTime"},
    ];
    induce("编码规则报表", column, pageData.value.tableList);
    skyMsgSuccess("导出成功");
    method.handleListPage();
  },
  /** 是否多选 */
  handleSelectionChange: (selection) => {
    pageData.value.ids = selection.map((item) => item.RecordId);
    pageData.value.single = selection.length !== 1; // 单选
    pageData.value.multiple = !selection.length; // 多选
  },
  /** 表格表头 */
  handleListMeter: async () => {
    const data = apiParam("2.0", "SYS.UserColumnDefineDAL.Query",
      [{UserCode: userStore.userid, Context: route.path}]);
    try {
      const res = await codeRulesApi(data);
      pageData.value.column = res.data.Columns.map(item => {
        return {
          title: item.DisplayCaption,
          dataIndex: item.DisplayFieldName,
          IsVisible: item.IsVisible,
        }
      });
    } catch (error) {
      skyMsgError("数据查询失败，请刷新重试🌻");
    }
  },
  /** 数据表格 */
  handleListPage: async () => {
    const data = apiParam("2.0", "PLM.CodeRulesDAL.Querybypage",
      [pageData.value.codeRulesParams, pageData.value.pageParams]);
    try {
      pageData.value.loading = true;
      pageData.value.tableList = [];
      const res = await codeRulesApi(data);
      pageData.value.total = res.data.recordsTotal;
      pageData.value.tableList = res.data.data;
      pageData.value.loading = false;
    } catch (error) {
      skyMsgError("数据查询失败，请刷新重试🌻");
    }
  },
  /** 打开来源参数 */
  handleOpenWindow: (title, data) => {
    // 打开弹出框
    skyWindowRef.value.skyOpen();
    // 判断参数
    pageData.value.windowParam.Code = "Dictionary";
    pageData.value.windowParam.Seq = "0001";
    // 标题
    pageData.value.windowTitle = title;
    pageData.value.windowObj = data;
    // 获取来源条件
    getNewInfo(pageData.value.windowParam).then(res => {
      pageData.value.windowCond = res;
      method.dealWindowData(title, res);
    });
  },
  /** 处理条件 */
  dealWindowData: (title, value) => {
    value.Conditions[1].ConValue = pageData.value.windowObj.CodeParaName;
  },
  /** 选择指定来源参数 */
  handleWindowConfirm: (val) => {
    let index = 0;
    pageData.value.form.ItembyParam.forEach((item, i) => {
      if (item.CodeParaName === pageData.value.windowObj.CodeParaName) {
        index = i;
        item.CodeNameValue = val.DicName;
        item.CodeParaValue = val.DicCode;
      }
    });
    method.handleDealItem(index);
    pageData.value.windowTitle = "";
    pageData.value.windowObj = {};
    pageData.value.windowParam = {};
    pageData.value.windowCond = {};
    skyWindowRef.value.skyQuickClose();
  },
  /** 取消来源参数 */
  handleWindowCancel: () => {
    skyWindowRef.value.skyClose();
  },
});
onMounted(() => {
  method.handleListTree();
  method.handleListMeter();
  method.handleListPage();
});
</script>

<!-- 编码规则 -->
<template>
  <div class="sky-flex">
    <div class="treeList sky-flex">
      <SkyCard>
        <SkyTree
          tree-name="物料类别"
          :props="pageData.props"
          :treeData="pageData.treeData"
          node-key="ProTypeCode"
          @currentChange="method.handleCurrentChange"
        ></SkyTree>
      </SkyCard>
    </div>
    <div class="tableList sky-flex">
      <SkyCard>
        <!-- 搜索条件 -->
        <el-form v-show="pageData.showSearch" :inline="true">
          <el-form-item label="关键字" prop="keyWord">
            <el-input
              style="width: 240px"
              placeholder="请输入关键字"
              v-model="pageData.searchParams.keyWord"
              clearable
              @keyup.enter.native="method.handleListKey"
            ></el-input>
          </el-form-item>
          <el-form-item label="排序" prop="sort">
            <el-select v-model="pageData.searchParams.sort" style="width: 240px" clearable
                       @keyup.enter.native="method.handleListPage">
              <el-option label="升序" value="asc"/>
              <el-option label="降序" value="desc"/>
            </el-select>
          </el-form-item>
          <el-form-item label="是否显示管理字段" prop="manage">
            <el-checkbox v-model="pageData.searchParams.manage"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="search" plain v-throttle="method.handleSearch">搜索</el-button>
            <el-button type="danger" icon="refresh" plain v-debounce="method.resetSearch">重置</el-button>
          </el-form-item>
        </el-form>
        <!-- 表格头部按钮 -->
        <el-row :gutter="10">
          <el-col :span="1.5">
            <el-button type="primary" icon="plus" plain @click="method.handleAdd()">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="delete" plain @click="method.handleBatchDelete()" :disabled="pageData.multiple">
              删除
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" icon="edit" plain @click="method.handleUpdate()" :disabled="pageData.single">修改
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" icon="download" plain @click="method.handleDerive">导出</el-button>
          </el-col>
          <SkyToolbar v-model:showSearch="pageData.showSearch" v-model:showColumns="pageData.showTable"
                      @refreshTable="method.handleListPage"></SkyToolbar>
        </el-row>
        <br/>
        <!-- 数据表格 -->
        <el-table
          v-loading="pageData.loading"
          border
          :data="pageData.tableList"
          empty-text="暂时没有数据哟🌻"
          @selection-change="method.handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column v-if="fieldVisible('编码分类', pageData.showTable)" label="编码分类" prop="RuleType"
                           width="150" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column v-if="fieldVisible('类别编号', pageData.showTable)" label="类别编号" prop="ClassCode"
                           width="150" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column v-if="fieldVisible('类别名称', pageData.showTable)" label="类别名称" prop="ClassName"
                           width="150" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column v-if="fieldVisible('规则编号', pageData.showTable)" label="规则编号" prop="RuleCode"
                           width="150" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column v-if="fieldVisible('规则名称', pageData.showTable)" label="规则名称" prop="RuleName"
                           width="150" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column v-if="fieldVisible('有效码', pageData.showTable)" label="有效码" prop="Isvalid"
                           width="150" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column v-if="fieldVisible('日期', pageData.showTable)" label="日期" prop="BillDate" width="150" align="center"
                           :show-overflow-tooltip="true">
            <template #default="scope">
              {{ changeDateFormat(scope.row.BillDate, "YYYY-MM-DD") }}
            </template>
          </el-table-column>
          <el-table-column v-if="fieldVisible('状态', pageData.showTable)" label="状态" prop="State" width="120" align="center"
                           :show-overflow-tooltip="true">
            <template #default="scope">
              <SkyTag :tagOptions="stateOptions" :value="scope.row.State"></SkyTag>
            </template>
          </el-table-column>
          <el-table-column v-if="fieldVisible('备注', pageData.showTable)" label="备注" prop="Remark" width="180" align="center"
                           :show-overflow-tooltip="true"></el-table-column>
          <el-table-column v-if="pageData.searchParams.manage" label="录入人" prop="Creator" width="130"
                           align="center"></el-table-column>
          <el-table-column v-if="pageData.searchParams.manage" label="录入时间" prop="CreateTime" width="200" align="center"
                           :show-overflow-tooltip="true">
            <template #default="scope">
              {{ changeDateFormat(scope.row.CreateTime, "YYYY-MM-DD hh:mm:ss") }}
            </template>
          </el-table-column>
          <el-table-column v-if="pageData.searchParams.manage" label="修改人" prop="LastModifier" width="130"
                           align="center"></el-table-column>
          <el-table-column v-if="pageData.searchParams.manage" label="修改时间" prop="LastModifyTime" width="200" align="center"
                           :show-overflow-tooltip="true">
            <template #default="scope">
              {{ changeDateFormat(scope.row.LastModifyTime, "YYYY-MM-DD hh:mm:ss") }}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="120" fixed="right">
            <template #default="{ row }">
              <el-tooltip content="修改🌻" placement="top">
                <el-button
                  type="primary"
                  icon="Edit"
                  circle
                  plain
                  @click="method.handleUpdate(row)"
                ></el-button>
              </el-tooltip>
              <el-tooltip content="删除🌻" placement="top">
                <el-button
                  type="danger"
                  icon="Delete"
                  circle
                  plain
                  @click="method.handleDelete(row)"
                ></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <br/>
        <!-- 分页 -->
        <el-pagination
          v-model:current-page="pageData.pageParams.pageIndex"
          v-model:page-size="pageData.pageParams.pageSize"
          v-show="pageData.total > 0"
          background
          :page-sizes="[10, 20, 50, 100, 200]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageData.total"
          @size-change="method.handleListPage"
          @current-change="method.handleListPage"
        />
        <!-- 添加 OR 修改 -->
        <SkyDialog
          ref="skyDialogRef"
          :title="pageData.title"
          @skyConfirm="method.handleConfirm"
          @skyCancel="method.handleCancel"
          :loading="pageData.confirmLoading"
          :fullscreen="true"
          :footer-hidden="false"
          :height="700"
        >
          <template #content>
            <div style="height: 300px; display: flex">
              <div style="width: 60%">
                <SkyCard>
                  <el-form ref="formRef" :rules="pageData.rules" :model="pageData.form" label-width="80px" status-icon>
                    <el-row>
                      <el-col :xs="{ span: 24 }" :sm="{ span: 12 }">
                        <el-form-item label="编码分类" prop="RuleType">
                          <el-select v-model="pageData.form.RuleType" @change="method.handleChangeRuleType" clearable>
                            <el-option
                              v-for="item in ruleTypeOptions"
                              :key="item.label"
                              :label="item.label"
                              :value="item.value"
                            />
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="{ span: 24 }" :sm="{ span: 12 }">
                        <el-form-item label="日期" prop="BillDate" class="p-l-10px">
                          <el-date-picker style="width: 100%;" v-model="pageData.form.BillDate" type="date"
                                          placeholder="请选择日期"
                                          clearable/>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :xs="{ span: 24 }" :sm="{ span: 12 }">
                        <el-form-item label="规则编号" prop="RuleCode">
                          <el-input v-model="pageData.form.RuleCode" placeholder="请输入规则编号" clearable/>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="{ span: 24 }" :sm="{ span: 12 }">
                        <el-form-item label="规则名称" prop="RuleName" class="p-l-10px">
                          <el-input v-model="pageData.form.RuleName" placeholder="请输入规则名称" clearable/>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :xs="{ span: 24 }" :sm="{ span: 12 }">
                        <el-form-item label="物料类别" prop="ClassName">
                          <el-tree-select
                            v-model="pageData.form.ClassName"
                            node-key="ProTypeCode"
                            :data="pageData.treeData"
                            :props="pageData.props"
                            check-strictly
                            @currentChange="method.handleChangeClass"
                          />
                        </el-form-item>
                      </el-col>
                      <el-col :xs="{ span: 24 }" :sm="{ span: 12 }">
                        <el-form-item label="序号间隔" prop="SNumberInterval" class="p-l-10px">
                          <el-input-number style="width: 100%;" v-model="pageData.form.SNumberInterval"/>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :xs="{ span: 24 }" :sm="{ span: 12 }">
                        <el-form-item label="序号长度" prop="SNumberLength">
                          <el-input-number style="width: 100%;" v-model="pageData.form.SNumberLength"/>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="{ span: 24 }" :sm="{ span: 12 }">
                        <el-form-item label="起始序号" prop="FirstSNumber" class="p-l-10px">
                          <el-input-number style="width: 100%;" v-model="pageData.form.FirstSNumber"/>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :xs="{ span: 24 }" :sm="{ span: 24 }">
                        <el-form-item label="备注" prop="Remark">
                          <el-input v-model="pageData.form.Remark" :rows="2" type="textarea" placeholder="请输入备注"/>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-form>
                </SkyCard>
              </div>
              <div style="width: 40%">
                <div class="sky-flex">
                  <SkyCard>
                    <el-table
                      border
                      :data="pageData.form.ItembyParam"
                      empty-text="暂时没有数据哟🌻"
                    >
                      <el-table-column label="参数" prop="CodeParaName" width="130" align="center"
                                       :show-overflow-tooltip="true"></el-table-column>
                      <el-table-column label="值" prop="CodeNameValue" width="180" align="center"
                                       :show-overflow-tooltip="true">
                        <template #default="scope">
                          <el-input v-if="scope.row.ParaSourceType === '字典'"
                                    v-model="scope.row.CodeNameValue" placeholder="请选择值" clearable>
                            <template #append>
                              <el-button :icon="More" @click="method.handleOpenWindow(scope.row.CodeParaName, scope.row)"/>
                            </template>
                          </el-input>
                          <el-input v-else v-model="scope.row.CodeNameValue" placeholder="请输入值" clearable/>
                        </template>
                      </el-table-column>
                      <el-table-column label="类型" prop="SourceType" width="150" align="center"
                                       :show-overflow-tooltip="true">
                        <template #default="scope">
                          <el-select v-model="scope.row.SourceType" @change="method.handleChangeSourceType(scope.row)" clearable>
                            <el-option label="不参与" :value="0"/>
                            <el-option label="不参与编码" :value="1"/>
                            <el-option label="参与编码" :value="2"/>
                          </el-select>
                        </template>
                      </el-table-column>
                      <el-table-column label="是否必填" prop="IsMustFull" width="130" align="center"
                                       :show-overflow-tooltip="true">
                        <template #default="scope">
                          <el-select v-model="scope.row.IsMustFull" clearable>
                            <el-option label="否" :value="0"/>
                            <el-option label="是" :value="1"/>
                          </el-select>
                        </template>
                      </el-table-column>
                    </el-table>
                  </SkyCard>
                </div>
              </div>
            </div>
            <div class="sky-flex">
              <SkyCard>
                <el-row :gutter="10">
                  <el-col :span="1.5">
                    <el-button type="primary" icon="plus" plain @click="method.handleAddItems">新增行</el-button>
                  </el-col>
                </el-row>
                <br/>
                <el-table
                  border
                  :data="pageData.form.Items"
                  empty-text="暂时没有数据哟🌻"
                >
                  <el-table-column label="序号" prop="Sort" width="150" align="center">
                    <template #default="scope">
                      <el-input-number style="width: 100%;" v-model="scope.row.Sort"/>
                    </template>
                  </el-table-column>
                  <el-table-column label="名称" prop="CodeParaName" align="center">
                    <template #default="scope">
                      <el-input v-model="scope.row.CodeParaName" placeholder="请输入名称" clearable/>
                    </template>
                  </el-table-column>
                  <el-table-column label="编码值" prop="CodeParaValue" align="center">
                    <template #default="scope">
                      <el-input v-model="scope.row.CodeParaValue" placeholder="请输入编码值" clearable/>
                    </template>
                  </el-table-column>
                  <el-table-column label="名称值" prop="CodeNameValue" align="center">
                    <template #default="scope">
                      <el-input v-model="scope.row.CodeNameValue" placeholder="请输入名称值" clearable/>
                    </template>
                  </el-table-column>
                  <el-table-column label="连接符" prop="Linkstr" align="center">
                    <template #default="scope">
                      <el-input v-model="scope.row.Linkstr" placeholder="请输入连接符" clearable/>
                    </template>
                  </el-table-column>
                  <el-table-column label="备注" prop="Remark" align="center">
                    <template #default="scope">
                      <el-input v-model="scope.row.Remark" placeholder="请输入备注" clearable/>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" prop="Operate" align="center">
                    <template #default="scope">
                      <el-tooltip content="删除🌻" placement="top">
                        <el-button
                          type="danger"
                          icon="Delete"
                          circle
                          plain
                          @click="method.handleDeleteItems(scope.row)"
                        ></el-button>
                      </el-tooltip>
                    </template>
                  </el-table-column>
                </el-table>
              </SkyCard>
            </div>
          </template>
        </SkyDialog>
        <!-- 来源参数 -->
        <SkyWindow
          ref="skyWindowRef"
          :title="pageData.windowTitle"
          :condition="pageData.windowCond"
          @skyConfirm="method.handleWindowConfirm"
          @skyCancel="method.handleWindowCancel"
        >
        </SkyWindow>
      </SkyCard>
    </div>
  </div>
</template>

<style scoped lang="scss">
.sky-flex {
  flex-direction: row;

  .treeList {
    width: 18%;
  }

  .tableList {
    width: 82%;
  }

  .formTree {
    width: 23%;
  }

  .form {
    width: 77%;
  }
}
</style>
